package com.example.usercenter.sys.web;

import com.alibaba.fastjson.JSONObject;
import com.example.usercenter.common.base.ResponseData;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import com.example.usercenter.common.base.BaseRestController;
import com.example.usercenter.common.base.BaseService;
import com.example.usercenter.sys.service.DictService;
import com.example.usercenter.sys.entity.Dict;

@RestController
@RequestMapping(value="/dict")
public class DictController extends BaseRestController<Dict, Long> {
    @Autowired
    private DictService dictService;

    protected BaseService<Dict, Long> getService(){
            return dictService;
    }

    @RequestMapping(value="/reloadCache")
    @ResponseBody
    public ResponseData reloadCache(){
        dictService.cacheInit();
        return new ResponseData(true, "重新加载数据字典成功");
    }

    @PreAuthorize("hasAuthority('DICT')")
    @Override
    public ResponseData get(@PathVariable("id") Long id) {
        return super.get(id);
    }

    @PreAuthorize("hasAuthority('DICT')")
    @Override
    public ResponseData save(@RequestBody Dict entity) {
        return super.save(entity);
    }

    @PreAuthorize("hasAuthority('DICT')")
    @Override
    public ResponseData update(@RequestBody Dict entity) {
        return super.update(entity);
    }

    @PreAuthorize("hasAuthority('DICT')")
    @Override
    public ResponseData delete(@PathVariable("id") Long id) {
        return super.delete(id);
    }

    @PreAuthorize("hasAuthority('DICT')")
    @Override
    public ResponseData page(@RequestBody JSONObject params) {
        return super.page(params);
    }

    @Override
    public ResponseData query(@RequestBody JSONObject params) {
        if(params!=null){
            params = new JSONObject();
        }
        params.put("downLoad", "1");
        return super.query(params);
    }

    @PreAuthorize("hasAuthority('DICT')")
    @Override
    public ResponseData exists(@RequestBody JSONObject params) {
        return super.exists(params);
    }
}